/*
 * Serum
 *
 * @license      GNU Lesser General Public Licence see LICENCE-LGPL file or http://www.gnu.org/licenses/lgpl.html
 */

Ext.namespace('Serum.Ajax');

Serum.Ajax.request = function(config) {
    Ext.Ajax.request(Ext.apply({
        queue:      true,
        url:        Serum.Selector.get().requestUrl(),
        method:     'POST',
        callback:   function(options, success, response) {
                        var jsonResponse = Ext.util.JSON.decode(response.responseText);

                        if (jsonResponse.exception != null) {
                            Serum.Exception.Handler.process(jsonResponse.exception);
                            success = false;
                        }

                        if (success) {
                            config.onSuccess.call(this, response);
                        } else if (typeof config.onFailure === 'function') {
                            config.onFailure.call(this, response);
                        }
                    }
    }, config));
};